package com.codechen.scaffold.news.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codechen.scaffold.common.domain.Result;
import com.codechen.scaffold.news.domain.request.NewsQueryRequest;
import com.codechen.scaffold.news.domain.vo.NewsBaseVO;
import com.codechen.scaffold.news.domain.vo.NewsVO;
import com.codechen.scaffold.news.service.INewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : wuweihong
 * @desc : TODO  请填写你的功能描述
 * @date : 2025-06-15
 */

@RestController
@RequestMapping("/news/frontend")
@Api(tags = "新闻前端接口")
public class NewsFrontendController {

	@Autowired
	private INewsService newsService;

	@GetMapping("/carousel")
	public Result<List<NewsBaseVO>> getCarousel() {
		return Result.success(newsService.listFeatures());
	}

	@PostMapping("/list/{pageNo}/{pageSize}")
	public Result getNewsPage(@PathVariable(value = "pageNo") Long pageNo,
	                          @PathVariable(value = "pageSize") Long pageSize,
	                          @RequestBody NewsQueryRequest queryRequest) {
		Page<NewsBaseVO> page = new Page<>(pageNo, pageSize);
		queryRequest.setStatus("published");
		IPage<NewsBaseVO> newsBaseVOIPage = newsService.queryList(page, queryRequest);
		return Result.success(newsBaseVOIPage);
	}

	@ApiOperation(value = "新闻详情")
	@GetMapping("/detail/{id}")
	public Result<NewsVO> getById(@PathVariable("id") Long id) {
		return Result.success(newsService.findNewsById(id));
	}


}
